package cn01;

import java.util.Random;

public class test03 {
    public static void main(String[] args) {
        Random r = new Random();
        int[] arr = new int[5];
        for (int i = 0; i < 5; i++) {
            arr[i] = r.nextInt(100) + 1;
        }

        getarr(arr);
        int getsum = getsum(arr);
        System.out.println("数组和为"+getsum);
        System.out.println("都为偶数的元素有:");
        index(arr);

    }
    public static void getarr ( int[] arr){
        System.out.print("[");
        for (int i = 0; i < 5; i++) {

            if (i == arr.length - 1) {
                System.out.print(arr[i]);
            } else {
                System.out.print(arr[i] + ",");
            }

        }
        System.out.println("]");
    }


    public static int getsum(int[] arr){
        int sum = 0;
        for (int i = 0; i < 5; i++) {
            sum  +=arr[i];
        }
        return sum;
    }

     public static void index(int [] arr){
         for (int i = 0; i < 5; i++) {
             if (i%2==0 && arr[i]%2==0){
                 System.out.println(arr[i]);
             }
         }
    }
}